package cn.bigcontainer.alt.meta.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import cn.bigcontainer.alt.common.entity.BigMap;
import cn.bigcontainer.alt.common.exception.BigResultCode;
import cn.bigcontainer.alt.common.util.BigConstant;
import cn.bigcontainer.alt.meta.service.RequestJsonService;

@Controller
@RequestMapping("/meta/requestjson")
@SessionAttributes(BigConstant.SESSION_USER)
public class RequestJsonController {

	@Autowired
	private RequestJsonService requestJsonService;

	/**
	 * 执行sql
	 * @param req
	 * @param map
	 * @return
	 */
    @RequestMapping("/sql")
	@ResponseBody
    public BigResultCode executeSql (@RequestParam Map<String, Object> req, Map<String, Object> map) {
        requestJsonService.executeSql(new BigMap<String, Object>().bigPutAll(req));
        return BigResultCode.getSuccessCode();
    }
    
    /**
	 * 修改MObject的部分属性
	 * @param req
	 * @param map
	 * @return
	 */
    @RequestMapping("/object")
	@ResponseBody
    public BigResultCode updateObject (@RequestParam Map<String, Object> req, Map<String, Object> map) {
        requestJsonService.updateObject(new BigMap<String, Object>().bigPutAll(req));
        return BigResultCode.getSuccessCode();
    }
}
